// ----------------------------------
// RSDK Project: Sonic 1 Forever X Doki Doki Literature Club
// Script Description: BG
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 1 : TYPE_SEGA
private alias 75 : SPACING_VALUE

private alias object.value0 : object.timer
private alias object.value1 : object.xScroll
private alias object.value2 : object.menuControlPos
private alias object.value3 : slot.player
private alias object.value4 : slot.lives
private alias object.value5 : slot.score
private alias object.value6 : slot.scoreBonus
private alias object.value7 : slot.stage
private alias object.value8 : slot.emeralds
private alias object.value9 : slot.nextSpecial
private alias object.value10 : slot.continues
private alias object.value11 : slot.read
private alias object.value12 : slot.handframe
private alias object.value13 : slot.blinkframe
private alias object.value14 : slot.arrowflash
private alias object.value15 : slot.partnerhandframe
private alias object.value16 : slot.partnerblinkframe
private alias object.value17 : slot.new

// Function declarations
reserve function SonicIdle
reserve function TailsIdle
reserve function KnuxIdle
reserve function SonicTailsIdle
reserve function KnuxTailsIdle
reserve function AmyIdle

function SonicIdle
	temp0 = object.xpos
	temp0 += 40
	temp1 = object.ypos
	temp1 += 48
	DrawSpriteScreenXY(33, temp0, temp1)

	arrayPos0 = object.menuControlPos
	if object.propertyValue == object[arrayPos0].value9
		if slot.blinkframe == 0
			rand(slot.blinkframe, 480)
			slot.blinkframe += 120
		else
			slot.blinkframe--
		end if

		temp2 = slot.blinkframe
		temp2 >>= 2
		switch temp2
			case 1
			case 3
				DrawSpriteScreenXY(36, temp0, temp1)
				break
			case 2
				DrawSpriteScreenXY(37, temp0, temp1)
				break
		end switch

		slot.handframe++
		slot.handframe%= 20
	end if

	if slot.handframe < 10
		DrawSpriteScreenXY(34, temp0, temp1)
	else
		DrawSpriteScreenXY(35, temp0, temp1)
	end if
end function

event ObjectMain
	if slot.read == 0
		arrayPos0 = object.propertyValue
		arrayPos0 <<= 3
		arrayPos0 += 1000

		slot.player = saveRAM[arrayPos0]
		arrayPos0++
		slot.lives = saveRAM[arrayPos0]
		arrayPos0++
		slot.score = saveRAM[arrayPos0]
		arrayPos0++
		slot.scoreBonus = saveRAM[arrayPos0]
		arrayPos0++
		slot.stage = saveRAM[arrayPos0]
		arrayPos0++
		slot.emeralds = saveRAM[arrayPos0]
		arrayPos0++
		slot.nextSpecial = saveRAM[arrayPos0]
		arrayPos0++
		slot.continues = saveRAM[arrayPos0]

		if slot.stage == 0
			slot.new = 1
		else
			slot.new = 0
		end if
		slot.read = 1
	end if
end event


event ObjectDraw
	if slot.new == 1
		DrawRect(object.xpos, object.ypos, 86, 48, color7, color6, color7, 255)
	else
		switch slot.player
		case 0
			temp0 = color7
			temp1 = color7
			temp2 = 0
			break
		default
			temp0 = color3
			temp1 = color3
			temp2 = color5
			break
		end switch

		DrawRect(object.xpos, object.ypos, 86, 48, temp0, temp1, temp2, 255)

		switch slot.player
			case 0
				CallFunction(SonicIdle)
				break

		end switch
	end if

	arrayPos0 = object.menuControlPos
	if object.propertyValue == object[arrayPos0].value9
		temp0 = object.xpos
		temp0 -= 3
		DrawRect(temp0, object.ypos, 2, 48, color7, color6, color7, 255)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("DDLCMenu/SaveSelect.gif")

	//Popup Sprites
	SpriteFrame(-12, -12, 30, 12, 546, 140) //0 Sonic 0
	SpriteFrame(-13, -23, 31, 23, 545, 153) //1 Sonic 1
	SpriteFrame(-13, -27, 31, 27, 545, 177) //2 Sonic 2
	SpriteFrame(-14, -27, 34, 27, 542, 205) //3 Sonic 3
	SpriteFrame(-14, -28, 34, 28, 542, 233) //4 Sonic 4
	SpriteFrame(-14, -28, 35, 28, 541, 262) //5 Sonic 5
	SpriteFrame(-14, -28, 35, 28, 541, 291) //6 Sonic 6
	SpriteFrame(-14, -28, 35, 28, 541, 320) //7 Sonic 7
	SpriteFrame(-14, -28, 35, 28, 541, 349) //8 Sonic 8
	
	SpriteFrame(-14, -10, 25, 10, 466, 150) //9 Tails 0
	SpriteFrame(-16, -20, 30, 20, 461, 161) //10 Tails 1
	SpriteFrame(-22, -25, 42, 25, 449, 182) //11 Tails 2
	SpriteFrame(-22, -27, 42, 27, 449, 208) //12 Tails 3
	SpriteFrame(-24, -27, 46, 27, 445, 236) //13 Tails 4
	SpriteFrame(-25, -27, 46, 27, 445, 264) //14 Tails 5
	SpriteFrame(-25, -27, 45, 27, 445, 292) //15 Tails 6	
	
	SpriteFrame(-14, -8, 30, 8, 493, 154) //16 Amy 0
	SpriteFrame(-17, -14, 36, 14, 493, 163) //17 Amy 1
	SpriteFrame(-18, -28, 37, 28, 493, 178) //18 Amy 2
	SpriteFrame(-17, -28, 35, 28, 493, 207) //19 Amy 3
	SpriteFrame(-22, -28, 41, 28, 493, 236) //20 Amy 4
	SpriteFrame(-28, -28, 47, 28, 493, 265) //21 Amy 5
	SpriteFrame(-30, -28, 49, 28, 491, 294) //22 Amy 6
	SpriteFrame(-31, -28, 50, 28, 490, 323) //23 Amy 7
	SpriteFrame(-31, -28, 50, 28, 526, 378) //24 Amy 8
	SpriteFrame(-31, -28, 50, 28, 526, 407) //25 Amy 9

	SpriteFrame(-17, -14, 33, 14, 411, 146) //26 Knux Base
	SpriteFrame(-17, -22, 36, 22, 408, 161) //27 Knux Base
	SpriteFrame(-18, -25, 35, 25, 409, 184) //28 Knux Base
	SpriteFrame(-18, -28, 38, 28, 406, 210) //29 Knux Base
	SpriteFrame(-21, -28, 41, 28, 403, 239) //30 Knux Base
	SpriteFrame(-23, -28, 45, 28, 398, 268) //31 Knux Base

	SpriteFrame(-34, -30, 68, 30, 94, 62) //32 Sonic Frame
	SpriteFrame(-14, -28, 44, 28, 532, 94) //33 Sonic Base
	SpriteFrame(9, -16, 11, 16, 553, 123) //34 Sonic Hand 1
	SpriteFrame(7, -16, 11, 16, 565, 123) //35 Sonic Hand 2
	SpriteFrame(-13, -18, 17, 13, 517, 123) //36 Sonic Blink 1
	SpriteFrame(-13, -18, 17, 13, 535, 123) //37 Sonic Blink 2
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
